<template>
  <div class="age-box">
    <div class="age-top">
      <p class="title">年龄比列</p>
      <p class="bg"></p>
    </div>
    <div class="age-charts" ref="agePol"></div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
// 引入echarts
import 'echarts-liquidfill'
import * as echarts from 'echarts'
// 设置组件名
defineOptions({
  name: 'Age',
})
// 生命周期钩子
onMounted(() => {
  let mycharts = echarts.init(agePol.value)
  const option = {
    legend: {
      top: 'center',
      right: '10%',
      itemGap: 20,
      orient: 'vertical',
      selectedMode: false,
      align: 'left',
      formatter: '{name}',
      textStyle: {
        color: '#fff',
      },
    },
    series: [
      {
        name: 'Access From',
        type: 'pie',
        left: '-20%',
        radius: ['40%', '90%'],
        avoidLabelOverlap: false,
        itemStyle: {
          borderRadius: 10,
          borderColor: '#fff',
          borderWidth: 2,
        },
        label: {
          show: true,
          position: 'inside',
          formatter: '{d}',
          color: '#fff',
        },
        data: [
          { value: 1048, name: '10岁以下' },
          { value: 735, name: '10 - 20岁' },
          { value: 580, name: '20 - 40岁' },
          { value: 484, name: '40 - 60岁' },
          { value: 300, name: '60岁以上' },
        ],
      },
    ],
  }
  mycharts.setOption(option)
})
// 获取dom实例
let agePol = ref()
</script>

<style scoped lang="scss">
.age-box {
  width: 100%;
  height: 100%;
  background: url(../../images/dataScreen-main-cb.png) no-repeat;
  background-size: 100% 100%;
  margin-bottom: 20px;
  .age-top {
    .title {
      color: #59b4e6;
      font-size: 20px;
    }

    .bg {
      width: 68px;
      height: 7px;
      background: url(../../images/dataScreen-title.png);
      margin-top: 20px;
    }
  }
  .age-charts {
    height: 200px;
  }
}
</style>
